//定义事件
const evenBus={
  callbacks:{}
}
//绑定事件
evenBus.on = function(str,callback){
  if(typeof str === 'string'){
    if(this.callbacks[str]){
      this.callbacks[str].push(callback)
    }else{
      this.callbacks[str] = [callback]
    }
  }
}
//触发事件
evenBus.emit = function(str,data){
  if(this.callbacks[str] && this.callbacks[str].length >0){
    this.callbacks[str].forEach(callback => {
        callback(data)      
    });
  }

}
//解绑事件
evenBus.off = function(eventName){
  if(eventName){
    delete this.callbacks[eventName]
  }else{
    this.callbacks = {}
  }

}